<section>
    <div class="container">
        <div class="row">
            <div class="span12">	            	
                <ul class="breadcrumb">
                    <li class="previous"><a href="<?php echo SITE_URL; ?>">Home /</a></li>                       
                    <li class="disable"><a href="javascript:void(0)">Inbox</a></li>
                </ul>                
            </div>
                <div id="AjaxLoader_id" style="display:none;" align="center">&nbsp;<img src="<?php echo ThemePath(); ?>/images/fancybox_loading@2x.gif" align="absmiddle"></div>
                <div class="span3">
                    <div class="tabBox">
                        <ul class="innerTab">
                           <?php 
								$imagePath = Message::ADMIN_ID;
                                if ($backenduserDetails->photo <> "") {
                                    $imgsrc = baseUrl() . '../../' . getUploadDir() . $imagePath . '/profile/minithumb/' . $backenduserDetails->photo;
                                } else {
                                    $imgsrc = baseUrl() . '../../upload/default-mini.png';
                                }
                                ?>
                               <li class="active"><a href="javascript:void(0);" onclick="return MessageByuseradminId();">
                                  <img src="<?php echo $imgsrc; ?>" title="<?php echo $backenduserDetails->first_name; ?>" alt="<?php echo $backenduserDetails->first_name; ?>" />
                                        <?php echo $backenduserDetails->first_name; ?></a>
                                </li>
								 
							<?php
                            if (count($inboxAll) > 0) {
							$i = 0;
                            foreach ($inboxAll as $inbox) {
                                $userDetails = Profiles::model()->findByAttributes(array('user_id' => $inbox->from_users_id));
                                $imagePath = $inbox->from_users_id;
                                if ($userDetails->photo <> "") {
                                    $imgsrc = baseUrl() . '../../' . getUploadDir() . $imagePath . '/profile/minithumb/' . $userDetails->photo;
                                } else {
                                    $imgsrc = baseUrl() . '../../upload/default-mini.png';
                                }
                                ?>
                                <li><a href="javascript:void(0);" onclick="return MessageByuserId(<?php echo $inbox->from_users_id; ?>,<?php echo $inbox->to_user_id; ?>,<?php echo $inbox->classes_id; ?>);">
                                        <img src="<?php echo $imgsrc; ?>" title="<?php echo $userDetails->first_name; ?>" alt="<?php echo $userDetails->first_name; ?>" />
                                        <?php echo $userDetails->first_name; ?></a>

                                </li>

                                <?php
                                $i++;
                            }
							}
                            ?>
                        </ul>
                        <div class="clear"></div>                   
                    </div>
                </div>
                <div class="span9">
                    <div class="msgBox">
                        <div class="padding20px" id="detailInbox">
					<?php if (count($inboxAlladmin) == 0) { ?>
					<input type="text" name="subject" id="subject_adminid" placeholder="Subject*" value="">
					<div  class="errorMessage" id="errorMessage_subject_adminid"></div>
					<div id="send_a_msg_box" class="reply-box">
					<textarea  id="message_text_adminid" name="message_text" placeholder="Message*"></textarea>
					<div  class="errorMessage" id="errorMessage_msg_adminid"></div>
					<div class="clear"></div>
					</div>												
					<p class="alignR remmarginB">
					<input type="button" value="Submit" name="yt1" class="btnbook" onclick="return replyAMailToUserAdmin()"></p>
						<?php }  ?>
						</div>
                    </div>

                </div>
                
        </div>
    </div>
</section>
<div>&nbsp;</div>
<script language="javascript">
$(document).ready(function() {
	MessageByuseradminId();
});
</script>
<script language="javascript">
    $(document).ready(function() {
        $(function() {
            $('.innerTab li a').click(function(e) {
                e.preventDefault();
                var $this = $(this);
                $this.closest('ul').children('li').removeClass('active');
                $this.parent().addClass('active');
            });
        });
    });

    function MessageByuserId(fromuid,touid,classid) {
        jQuery.ajax({
            'type': 'POST',
            'url': "<?php echo Yii::app()->createAbsoluteUrl("MailConversation/GetMessage"); ?>",
            data: 'classid=' + classid+'&fromuid=' + fromuid+'&touid=' + touid ,
            'success': function(data) {
                $('#detailInbox').html(data);
	   
            },
            'cache': false});

    }
    
    function MessageByuseradminId() {
	    $.ajax({
            'type': 'POST',
            'url': "<?php echo Yii::app()->createAbsoluteUrl("ContactAdmin/GetMessage"); ?>",
            data: '' ,
            'success': function(data) {
                $('#detailInbox').html(data);
	   
            },
            'cache': false});

    }
	
	
	function showMsgBlock(checkval) {
        if(checkval==1){$("#replybtn").hide();}else{$("#replybtn").show();}
        $("#send_a_msg_box").toggle('slow').show();
    }


    function replyAMailToUser(classcoursetype,classid, userid, getMessagesUID) {
        var subject = $("#subject_id").val();
        var msgval = $("#message_text_id").val();

        if (msgval == '') {
            $("#errorMessage_msg_id").text('Message  can not blank.')
            return false;
        }
        if(subject != '' && msgval != '') {
            jQuery.ajax({
                'type': 'POST',
                'url': "<?php echo Yii::app()->createAbsoluteUrl("MailConversation/sendMailTouser"); ?>",
                'data': "selectedUser=" + userid + "&subject=" + subject + "&msgval=" + msgval + "&classId=" + classid+ "&type=" + classcoursetype,
                'beforeSend': function(jqXHR, settings) {
                    $("#AjaxLoader_id").show();
                },
                'success': function(data) {
                    if($.trim(data)=='success') {
                        $("#AjaxLoader_id").hide();	
                        MessageByuserId(userid,getMessagesUID,classid);
                    }
                },
                'cache': false
            });
        }

    }
	
	function replyAMailToUserAdmin() {
        var subject = $("#subject_adminid").val();
        var msgval = $("#message_text_adminid").val();

        if (subject == '') {
            $("#errorMessage_subject_adminid").text('Subject can not blank.');
            return false;
        }else{
		    $("#errorMessage_subject_adminid").text('');
		}

        if (msgval == '') {
            $("#errorMessage_msg_adminid").text('Message can not blank.')
            return false;
        }else{
		    $("#errorMessage_msg_adminid").text('');
		}
        if(subject != '' && msgval != '') {
            jQuery.ajax({
                'type': 'POST',
                'url': "<?php echo Yii::app()->createAbsoluteUrl("ContactAdmin/sendMailTouser"); ?>",
                'data': "subject=" + subject + "&msgval=" + msgval,
                'beforeSend': function(jqXHR, settings) {
                    $("#AjaxLoader_id").show();
                },
                'success': function(data) {
					if($.trim(data)=='success') {
                        $("#AjaxLoader_id").hide();	
                        MessageByuseradminId();
                    }
                },
                'cache': false
            });
        }

    }


</script>